<?php

namespace App\Http\Controllers\Website;

use App\Http\Controllers\Controller;
use App\Http\Traits\TraitFront;
use App\Models\Article;
use App\Models\Category;
use App\Models\FriendLink;
use App\Models\Nav;
use App\Models\SystemConfig;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;

class IndexController extends Controller
{
    use TraitFront;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        // 请求路由
        $routes = \request()->path();
        //登录验证
        //$this->middleware('auth');
        //共享视图
        $navList    = Nav::cacheNav();
        // 网站配置
        $list = SystemConfig::where([
            ['status', '=', '1'],
            ['config_type', '=', '0']
        ])->select('key', 'value')->get();
        $config = [];
        foreach ($list as $key => $val) {
            $config[$val['key']] = $val['value'];
        }
        $links = FriendLink::query()
            ->where('status', 1)
            ->select('name', 'url')
            ->orderBy('sort', 'desc')
            ->get();
        View::share([
            'nav_list'      => $navList,
            'config' => $config,
            'links' => $links,
            'routes' => $routes,
        ]);
    }

    /**
     * Description:
     * User: Vijay
     * Date: 2019/8/4
     * Time: 16:30
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index(Request $request)
    {
        return view('website.index.index', [
        ]);
    }

    // 解决方案
    public function solutions(Request $request)
    {
        return view('website.index.solutions', [
        ]);
    }

    // 产品展示
    public function product_show(Request $request)
    {
        return view('website.index.product_show', [
        ]);
    }

    // 客户案例
    public function customer_case(Request $request)
    {
        return view('website.index.customer_case', [
        ]);
    }

    // 服务中心
    public function service_center(Request $request)
    {
        return view('website.index.service_center', [
        ]);
    }

    // 新闻动态
    public function news(Request $request)
    {
        $where = [
            ['status', '=', '1'],
        ];
        $hotArts = Article::where($where)->orderBy('click', 'desc')
            ->select('id', 'title', 'updated_at', 'description')
            ->paginate(5);
        $articles = Article::where($where)
            ->orderBy('created_at', 'desc')
            ->orderBy('click', 'desc')
            ->paginate(6);
        return view('website.index.news', [
            'hotArts'    => $hotArts,
            'articles'    => $articles,
        ]);
    }

    // 关于我们
    public function about_us(Request $request)
    {
        return view('website.index.about_us', [
        ]);
    }

    // 招贤纳士
    public function recruit(Request $request)
    {
        return view('website.index.recruit', [
        ]);
    }
}
